#include "Support.h"
#include "StateManager.h"
#include "MenuState.h"
#include "PlayState.h"
#include "OptionState.h"
#include "HelpState.h"
#include "AboutState.h"

void CMenuState::Init()
{
	m_select = 0;
}

void CMenuState::Release()
{

}

void CMenuState::Pause()
{

}

void CMenuState::Resume()
{

}

void CMenuState::Update()
{
	//Change the position of the cursor
	if (GIsKeyPress(KEY_DOWN))
	{
		if (m_select < 4)
		{
			m_select++;
		}
	}
	else if (GIsKeyPress(KEY_UP))
	{
		if (m_select > 0)
		{
			m_select--;
		}
	}

	//Change to respective state or exit game
	if (GIsKeyPress(KEY_SPACE))
	{
		if (m_select == 0)
		{
			CStateManager::GetInstance()->ChangeState(new CPlayState());
		}
		else if (m_select == 1)
		{
			CStateManager::GetInstance()->PushState(new COptionState());
		}
		else if (m_select == 2)
		{
			CStateManager::GetInstance()->PushState(new CHelpState());
		}
		else if (m_select == 3)
		{
			CStateManager::GetInstance()->PushState(new CAboutState());
		}
		else
		{
			exit(1);
		}
	}
}

void CMenuState::Draw()
{
	GPutStringToBufferWithMargin("Flow", 8, GColors::LIGHT_CYAN);

	//Show list option in menu
	GPutStringToBufferWithMargin("New Game", 12);
	GPutStringToBufferWithMargin("Option", 14);
	GPutStringToBufferWithMargin("How to play", 16);
	GPutStringToBufferWithMargin("About", 18);
	GPutStringToBufferWithMargin("Exit", 20);

	//Show the cursor
	GPutCharToBuffer(16, 9, 12 + m_select * 2, GColors::LIGHT_MAGENTA);
	GPutCharToBuffer(17, 29, 12 + m_select * 2, GColors::LIGHT_MAGENTA);
}